<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>加解密测试</title>
    <script src="JSEncrypt.js"></script>
    <script src="http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
    公钥：<textarea id="public_key">MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCHpNpch8Ykb/vh58SX8WEWL3sAu5JWj0JdLSnmv27sRFxAhZ1nxhppslNNOy6W/m9xmvkLFnXuVa4efw0N3vR08cHSKa7bDRBvgd/NdduoWmZElagiPAx/EklPcxM+vtWyOXr1ro5kIgblXTlX/WZRidKYPylTIcibZTdrwQ8ckwIDAQAB</textarea>
    要加密内容：<textarea id="encrypt_body">{"sdgd":4864}</textarea>
    <button id="submit">提交</button>
    返回内容：<textarea id="body"></textarea>
    解密返回内容：<textarea id="decrypt_body"></textarea>
    <script>
        var encryptor = new JSEncrypt();
        encryptor.setPublicKey('-----BEGIN PUBLIC KEY-----'
            +$('#public_key').html()
            +'-----END PUBLIC KEY-----')//设置公钥

        $('#submit').click(()=>{
            var rsaPassWord = encryptor.encrypt($('#encrypt_body').val());
            $.ajax({
                type:'post',
                url:'http://127.0.0.1:8080/a',
                contentType:'application/json',
                data:rsaPassWord,
                success:function (res){
                    $('#body').html(res);
                    $('#decrypt_body').val(encryptor.decrypt(res,'publicKey'))
                }
            })
        })
    </script>
</body>
</html>